package com.shu.pattern;

interface State {
    default void doWork() {
        System.out.println("默认正常工作");
    }
}

/**
 * @version V1.0
 * @description: 状态模式 -> 根据不同的状态做出不同的行为
 * @date 2021/8/18 17:04
 */
public class StatePattern {
    public static void main(String[] args) {
        Context boy = new Context().setState(new Sad());
        boy.doWork();

        boy.setState(new Happy());
        boy.doWork();
    }

}

class Happy implements State {
    @Override
    public void doWork() {
        System.out.println("高兴: 努力工作");
    }
}

class Sad implements State {
    @Override
    public void doWork() {
        System.out.println("悲伤: 无心工作");
    }
}

class Context {
    private State state;

    public Context setState(State state) {
        this.state = state;
        return this;
    }

    public void doWork() {
        state.doWork();
    }

}
